﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using QLKS10_11.BLL;
namespace QLKS10_11.GUI
{
    public partial class form_QLthietbi : Form
    {
        public form_QLthietbi()
        {
            InitializeComponent();
        }
        /******************************************CHUYEN FORM*********************************************************/
        private static form_QLthietbi _instance;
        public static form_QLthietbi Instance()
        {
            if (_instance == null)
            {
                _instance = new form_QLthietbi();
            }
            return _instance;
        }
        private void btn_qlthietbi_Click(object sender, EventArgs e)
        {
            form_main frm1 = form_main.Instance();
            frm1.Show();
            this.Hide();
        }

        private void form_QLthietbi_FormClosed(object sender, FormClosedEventArgs e)
        {
            form_main frm1 = form_main.Instance();
            frm1.Dispose();
        }
        /******************************************LOAD DU LIEU TU DATABASE*********************************************************/
        QLthietbi_BLL qlthietbi = new QLthietbi_BLL();
        private void form_QLthietbi_Load(object sender, EventArgs e)
        {
            qlthietbi.HienThi(gc_qlthietbi,bd_qlthietbi);
            /*khi load form len khong cho nguoi dung tu sua danh sach*/
            gridView1.OptionsBehavior.Editable = false;
            btn_luu.Enabled = false;
        }

        private void btn_them_Click(object sender, EventArgs e)
        {
            btn_luu.Enabled = true;
            gridView1.OptionsBehavior.Editable = true;
            DataRow row = qlthietbi.NewRow();
            row["tenphong"]="";
            row["matb"] = "";
            row["manvlap"] = "";
            row["soluong"] =1;
            qlthietbi.Add(row);
        }

        private void btn_xoa_Click(object sender, EventArgs e)
        {
            btn_luu.Enabled = true;
            if (gridView1.RowCount > 0)
            {
                if (MessageBox.Show("Ban co muon xoa thiet bi nay khong?", "Xoa trang bi thiet bi phong", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    bd_qlthietbi.BindingSource.RemoveCurrent();
                    qlthietbi.Save();
                }
            }
            else MessageBox.Show("Danh sach trang bi thiet bi cho phong rong.");
        }

        private void btn_sua_Click(object sender, EventArgs e)
        {
            btn_luu.Enabled = true;
            gridView1.OptionsBehavior.Editable = true;
        }

        private void btn_luu_Click(object sender, EventArgs e)
        {
            bd_qlthietbi.BindingSource.MoveNext();
            bindingNavigatorPositionItem.Focus();
            qlthietbi.Save();
            MessageBox.Show("Luu thanh cong");
        }

        private void btn_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
